<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page import="java.util.Calendar" %>
<% String title = "信息综合系统"; %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<title><%=title %>-通讯录管理</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-itunes-app" content="app-id=429849944"/>
<meta name="apple-touch-fullscreen" content="no"/>
<meta content="telephone=no" name="format-detection"/>
<meta name="apple-mobile-web-app-capable" content="no"/>
</head>

<!-- BEGIN BODY -->
<body class="fixed-top">

<jsp:include page="/common/headerPage.jsp"></jsp:include>
<!-- BEGIN CONTAINER 容器 -->
<div id="container" class="row-fluid">
    <!-- BEGIN SIDEBAR 侧边栏-->
    <jsp:include page="/common/left.jsp"></jsp:include>
    <!-- END SIDEBAR -->

    <!-- BEGIN PAGE -->
    <div id="main-content">
        <!-- BEGIN PAGE CONTAINER-->
        <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
            <div class="row-fluid">
                <div class="span12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title">通讯录管理</h3>
                    <ul class="breadcrumb" style="padding-bottom : 12px;">
                        <li><a href="${pageContext.request.contextPath}/user/index.do">首页</a>
                            <span class="divider">/</span></li>
                        <li class="active">通讯录管理</li>
                        <li class="pull-right search-wrap" >
                            <input type="button" class="btn  btn-info" onclick="toggleCondi();" id="show"
                                   value="隐藏筛选区域"/>
                            &nbsp;&nbsp;
                            <div class="btn-group pull-right" >
		                    <button class="btn dropdown-toggle" data-toggle="dropdown">更多 <i class="icon-angle-down"></i>
		                    </button>
		                    <ul class="dropdown-menu pull-right">
		                        <li><a href="${pageContext.request.contextPath}/mailList/download.do?i=<%=Math.random() %>">下载已筛选的记录</a></li>
		                        <li><a href="#" onclick="openUpload();">Excel批量上传N条</a></li>
		                        <li><a href="#" onclick="showOpen('','新增通讯录');">页面新增一条</a></li>
		                    </ul>
		                	</div>
                        </li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN BASIC PORTLET-->
            <div class="widget" >
                <div class="purple">
                <div class="row-fluid" >
                    <div class="clearfix" >
                    	<form action = "${pageContext.request.contextPath }/mailList/selectMailList.do" 
                    	       id = "filterForm" method="post">
                        <input type="text" class="span2" id="mailListId" name="id" placeholder="请填写ID" />
                        <input type="text" class="span2 typeahead" id="name" name="name" placeholder="请填写姓名"/>
                        <input type="text" class="span2 typeahead" id="mobilePhone" name="mobilePhone" placeholder="请填写手机号码" />
                        <input type="text" class="span2 typeahead" id="position" name="position" placeholder="请填写职位"/>
                        <input type="text" class="span2 typeahead" id="machineNumber" name="machineNumber" placeholder="请填写座机号码" />  
                        <input type="text" class="span2 typeahead" id="region" name="region" placeholder="请填写地区" /> 
                        <input type="text" class="span2 typeahead" id="email" name="email" placeholder="请填写邮箱" />      
                        <input type="text" class="span2 typeahead" id="faxNumber" name="faxNumber" placeholder="请填写传真号码" /> 
                        <select id="sex" name="sex" style="width:100px;">
                            <option value="">请选择性别</option>
                            <option value="男">男</option>
                            <option value ="女">女</option>
                        </select>
                        <input type="text" class="span3 typeahead" id="address" name="address" placeholder="请填写通讯地址" />     
                             
                        <input type="button" id="seach" name="seach" value="查询" class="btn  btn-primary"
                               style="margin-bottom: 10px;" onclick="ajaxGetMailList(1,8);"/>
                        <input type="reset" id="reset" name="reset" value="重置该页面" class="btn  btn-primary"
		                       style="margin-bottom: 10px;" onclick="resetf();"/>
		            </form>
                    </div>
                </div>
                
                <div id="errorInfoDiv" hidden="hidden">
					<table class="table table-striped table-hover table-bordered" style="font-size:11px;color:red;width:750px;margin:12px;">
						<thead>
							<tr>
								<td><b>出错行号</b></td>
								<td><b>出错标题</b></td>
								<td style="color:#479DA4;"><b>参考标准提示</b></td>
								<td><b>错误字段</b></td>
							</tr>
						</thead>
						<tbody id="error-body"></tbody>
					</table>
				</div>
              
               <div id="updateMailListForm" hidden>
               	   <div class="modal-body" style="height: 90%">
                    	<form action="${pageContext.request.contextPath }/mailList/changeMailList.do" method="post" id="mailListForm">
	                        <input type="text" class="span2" id="mailListIdU" name="id" placeholder="请填写ID" readonly="readonly"/>
	                        <span style="color:red;">*</span>&nbsp;
	                        <input type="text" class="span2 typeahead noNull" id="nameU" name="name" placeholder="请填写姓名"/>
	                        <span style="color:red;">*</span>&nbsp;
	                        <input type="text" class="span2 typeahead noNull" id="mobilePhoneU" name="mobilePhone" placeholder="请填写手机号码" />
	                        <span style="color:red;">*</span>&nbsp;
	                        <input type="text" class="span2 typeahead noNull" id="positionU" name="position" placeholder="请填写职位"/>
	                        <input type="text" class="span2 typeahead" id="machineNumberU" name="machineNumber" placeholder="请填写座机号码"/>  
	                        <span style="color:red;">*</span>&nbsp;
	                        <input type="text" class="span2 typeahead noNull" id="regionU" name="region" placeholder="请填写地区"/> 
	                        <input type="text" class="span2 typeahead" id="emailU" name="email" placeholder="请填写邮箱" />      
	                        <input type="text" class="span2 typeahead" id="faxNumberU" name="faxNumber" placeholder="请填写传真号码" /> 
	                        <br/><span style="color:red;">*</span>&nbsp;
	                        <select id="sexU" name="sex" class="input-medium m-wrap noNull">
	                            <option value="">请选择性别</option>
	                            <option value="男">男</option>
	                            <option value ="女">女</option>
	                        </select>
	                        <input type="text" class="span5 typeahead" id="addressU" name="address" placeholder="请填写通讯地址" />  
                        </form>
                    </div>
                </div>
                
                <div id="uploadFileForm" hidden>
                    <div class="modal-body" >
                         <form action="${pageContext.request.contextPath}/mailList/upload.do?i=<%=Math.random() %>"
								method="post" id="uploadForm" enctype="multipart/form-data">
								点击该按钮选择文件:<input type="file" name="excelFile" multiple="multiple"
									class="input-medium" id="file"><br />
						 </form>
                    </div>
                </div>
				
				<div class="row-fluid">
                	<div class="span12">
                    <!-- BEGIN ALERTS PORTLET-->
                    <div class="widget blue">
                        <div class="widget-title">
                            <h4><i class="icon-reorder"></i>通讯录查询清单列表
                                <a href="javascript:;" id="getProp" style ="color:white;margin-left:20px;">复制选中行id</a>
                            </h4>
                            <span class="tools">
								<a href="javascript:;" class="icon-chevron-down"></a>
							</span>
                        </div>
				    
                        <div class="widget-body" style="overflow:auto">
	                        <div class="pageBottom" style="text-align:center;">
	                            <input type="hidden" id="page-size" value="0"/>
	                            <div id="callBackPager" class="paging_bootstrap pagination"></div> 
	                        </div>
                        	<table class="table table-striped table-hover table-bordered" width="640px;"
                           		style="table-layout:fixed">
                                <thead>
	                               <tr>
	                                   <th style="width:15px;"><input type="checkbox" name="choiceAll" value="all" id ="allAndNotAll"/></th>
                                       <th width="30px">id</th>
	                                   <th width="80px">地区</th>
	                                   <th width="120px">职位</th>
	                                   <th width="60px">姓名</th>
	                                   <th width="30px">性别</th>
	                                   <th width="90px">座机号码</th>
	                                   <th width="90px">手机号码</th>
	                                   <th width="90px">传真号码</th>
	                                   <th width="120px">电子邮箱</th>
                                       <th width="180px">通讯地址</th>
	                               </tr>
                                </thead>
                                <tbody id="distribute-body">
                        		</tbody>
                            </table>
                        </div>

                    </div>
                    <!-- END ALERTS PORTLET-->
                	</div>
            	</div>
            	
            </div>
            </div>
            <!-- END BASIC PORTLET-->
        </div>
    </div>
</div>
</div>

<!-- BEGIN FOOTER -->
<jsp:include page="/common/footer.jsp"></jsp:include>
<!-- END FOOTER -->

<!-- BEGIN JAVASCRIPTS -->
<!-- Load javascripts at bottom, this will reduce page load time -->
<%--<script src="js/jquery-1.8.3.min.js"></script>--%>
<script src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.nicescroll.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.easy-pie-chart.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/jquery.sparkline.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/Chart.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.scrollTo.min.js"></script>
<!--common script for all pages-->
<script src="${pageContext.request.contextPath}/js/common-scripts.js"></script>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
<%--<script src = "${pageContext.request.contextPath}/js/jquery.min.js" > </script>--%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-multiselect.css" type="text/css"/>

<script src="${pageContext.request.contextPath}/js/bootstrap-typeahead.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/extendPagination.js"></script>
<script type="text/javascript" src="http://img3.job1001.com/js/ZeroClipboard/jquery.zclip.min.js"></script>

<!-- END JAVASCRIPTS -->
<!-- 自定义的script方法 -->
<script>
	$(document).ready(function () {
	    /*通过ID查询*/
	    $('#province').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择省份', enableFiltering: true, maxHeight: 300, buttonWidth: '100px'});
	    $('#type').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择用户类型',enableFiltering: true, maxHeight: 300,buttonWidth: '140px'});
	    $('#city').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择地市',enableFiltering: true, maxHeight: 300,buttonWidth: '100px'});
	    $('#county').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择区县',enableFiltering: true, maxHeight: 300,buttonWidth: '100px'});
   });

     if ( window.clipboardData ) {
         $('#getProp').click(function() {
             var ids = getProp();  
             if(selectedIds.trim().length>0){
         		   ids = selectedIds;
         	    }
             if(ids.trim().length>0){
                 window.clipboardData.setData("Text", ids);
                 $("#allAndNotAll").attr("checked", false);  
                 $("input[name='choice']:checkbox").each(function(){ 
                     $(this).attr("checked", false);  
               	});
                 layer.msg("复制成功！");
             }else{
                 layer.alert("您没有选中行！");
             }
         });
     } else {
         $("#getProp").zclip({
             path:'http://img3.job1001.com/js/ZeroClipboard/ZeroClipboard.swf',
             copy:function(){
                    var ids = getProp(); 
                    if(selectedIds.trim().length>0){
                		   ids = selectedIds;
                	    }
                    if(ids.trim().length>0){
                        return ids;
                    }else{
                        layer.msg("您没有选中行！");
                    }
                 },
             afterCopy:function(){
            	 $("#allAndNotAll").attr("checked", false);  
                 $("input[name='choice']:checkbox").each(function(){ 
                     $(this).attr("checked", false);  
               	});
            	 layer.msg("复制成功！");
           	}
         });
     }
</script>
<script type="text/javascript">
    //隐藏或显示筛选区
    function toggleCondi() {
        var text = $("#show").val();
        if (text == '显示筛选区域') {
            $("#show").val("隐藏筛选区域");
        } else {
            $("#show").val("显示筛选区域");
        }
        $(".clearfix").slideToggle();
    }

    //上传文件的大小和格式校验
    function uploadFile() {
    	var ret = false;
        var maxsize = 100 * 1024 * 1024;//100M
        var name = $("#file").val();
        var ext = name.substr(name.lastIndexOf('.') + 1);
        if (ext != 'xls' && ext != 'xlsx') {//文件格式验证
            layer.msg("文件后缀只能为.xls和.xlsx!");
            $("#file").val('');
            layer.closeAll('loading');
            clicked = true;
            return ret;
        }
        var names = document.getElementById("file");
        var sizes = names.files[0].size;
        if (maxsize < sizes) {  //文件大小验证
            $("#file").val('');
            layer.msg("文件大小不能超过100M!");
            clicked = true;
            return ret;
        }
        var formData = new FormData($("#uploadForm")[0]);
        layer.msg('拼命执行中，请稍等……', {icon: 16}, function(){
        	layer.closeAll();
        	layer.load(2);
        	$.ajax({
                type: "POST",
                url: $('#uploadForm').attr("action"),
                data: formData,
                cache: false,  
                async:true,
                dataType: "json",
                processData: false,
                contentType : false,
                success: function (result) {
                	var code = result.code;
                	$("#file").val("");
               		if(code==-2){//表示上传的excel格式有错误
               			errorInfo(result.msg);
               			ret = false;
                   	}else if(code==-3){	//登录用户失效
                   		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                   		ret = false;
                   	}else if(code==-1){
                   		layer.alert(result.msg);
                   	}else{	//上传成功
                   		layer.closeAll();
                		layer.alert("操作成功！\n"+result.msg);
                		ajaxGetMailList(1,8);
                		ret = "success";
                	}
               		return ret;
                },
                error: function (e) {
                	layer.closeAll('loading');
                    layer.msg("操作失败！");
                    ret = fasle;
                }
            });
        });
        layer.closeAll('loading');
        return ret;
    }

    function checkNull(type){
    	var noNull = $(".noNull");
    	if(type=='change'){
    		noNull = $("#mailListForm").find(".noNull");
    	}
		for(var i=0;i<noNull.length;i++){
			if(noNull[i].value==null||noNull[i].value==undefined||noNull[i].value==""){
				layer.msg("请完善带*号项！");
				return "false";
			}
		}
		return "true";
    }
    
    function errorInfo(items){
 	   var html = [];
 	   for (var i = 0; i < items.length; i++) {
 		   html.push("<tr>");
 		   html.push('<td>' + items[i].err_num.substring(items[i].err_num.indexOf("：")+1)+ '</td>');
            html.push('<td>' + formatData(items[i].err_title) + '</td>');
            html.push('<td style="color:#479DA4;">' + formatData(items[i].err_msg) + '</td>');
            html.push('<td>' + formatData(items[i].err_field) + '</td>');
            html.push('</tr>');
 	   }
 	   var mainObj = $('#error-body');
        mainObj.empty();
        mainObj.html(html.join(''));
        
        var errorInfoHtml = $("#errorInfoDiv").html();
 			layer.open({
 	   	        title: ['错误信息', 'font-size:18px;'],
 	   	        type:1,
 	   	        content: errorInfoHtml //这里content是一个普通的String
 	   	        ,cancel: function(){
 	   	        	layer.closeAll('loading');
 	   	        //	openUpload();
 	   	        	return true;
 	   	        }
 	   	        ,area: ['800px', '400px']
 	   	    });
 		
   		$("#error-info").removeAttr("hidden");
    }

    //异步请求获取符合筛选条件的流向记录
    function ajaxGetMailList(pageNumber, pageSize) {
        layer.load(2);
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath }/mailList/selectMailList.do?pageNumber="+pageNumber+"&pageSize="+pageSize+"&t=" + Math.random(),
            data: $("#filterForm").serialize(),
            dataType: "json",
            success: function (result) {
                $(".pageBottom").css('display', 'none');
                $("#distribute-body").html("");
                if(result!=null){
                	if(result.code==-3){	//登录用户失效
                   		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                   	}else if (result.total == 0) {
                        layer.msg("筛选后的记录数为零！")
                    } else {
                    	$("#distribute-body").html("");
                        if (result.pageNum == 1) {
                            $('#callBackPager').extendPagination({
                                totalCount: result.total,
                                showPage: 5,
                                pageNum: result.pageNum,
                                limit: result.pageSize,
                                callback: function (curr, limit, totalCount) {
                                	ajaxGetMailList(curr, limit);
                                }
                            });
                        }
                        $(".pageBottom").css('display', 'block');
                        createTable(result.pageNum, result.pageSize, result.total, result.list);
                        $("#pageNumber").text(result.pageNum);
                    }
                }else{
                    layer.closeAll('loading');
                    layer.alert("查询结果为null！");
                }
                layer.closeAll('loading');
            },
            error: function (e) {
                layer.closeAll('loading');
                layer.msg("操作失败！");
            }
        });
    };

    //动态创建table
    function createTable(currPage, limit, total, items) {
        var html = [], showNum = limit;
        if (total - (currPage * limit) < 0) showNum = total - ((currPage - 1) * limit);
        for (var i = 0; i < showNum; i++) {
            html.push("<tr ondblclick=\"showOpen('"+items[i].id+"','修改通讯录')\" >");
            html.push('<td><input type="checkbox" name="choice" value="'+items[i].id+'"/></td>');
            html.push('<td>' + formatData(items[i].id) + '</td>');
            html.push('<td>' + formatData(items[i].region) + '</td>');
            html.push('<td>' + formatData(items[i].position) + '</td>');
            html.push('<td>' + formatData(items[i].name) + '</td>');
            html.push('<td>' + formatData(items[i].sex) + '</td>');
            html.push('<td>' + formatData(items[i].machineNumber) + '</td>');
            html.push('<td>' + formatData(items[i].mobilePhone) + '</td>');
            html.push('<td>' + formatData(items[i].faxNumber) + '</td>');
            html.push('<td>' + formatData(items[i].email) + '</td>');
            html.push('<td>' + formatData(items[i].address) + '</td>');
            html.push('</tr>');
        }
        var mainObj = $('#distribute-body');
        mainObj.empty();
        mainObj.html(html.join(''));
    };

    //格式化无效数据
    function formatData(data) {
        if (data && data != null) {
            return data;
        } else {
            return "";
        }
    }
    
  //查询按钮绑定回车键
    $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#seach').click();
        }
    });

</script>
<!-- END BODY -->
<script>
    var htmls = $("#updateMailListForm").html();
    var uploadFileHtml = $("#uploadFileForm").html();
    var ret = null;
    function showOpen(id,type) {
        if("修改通讯录"==type){
            $.ajax({
                type: "POST",
                async:false,//同步
                url: "${pageContext.request.contextPath }/mailList/selectMailListByID.do?t=" + Math.random(),
                data: {id:id},
                dataType: "json",
                success: function (result) {
                	if(result.code==-3){	//登录用户失效
                   		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                   	}else {
                    	ret = result;
                   	}
                },
                error: function (e) {
                    layer.closeAll('loading')
                    layer.msg("操作失败！");
                }
            });
        }
        $("#updateMailListForm").remove();
        layer.open({
            title: [type+'<span style="color:red;font-size:12px;margin-left:10px;">*表示该项必填</span>', 'font-size:18px;'],
            type:1,
            content: htmls, //这里content是一个普通的String
            btn: ['确认', '取消'],
            yes: function(index, layero){
            	//非空验证
            	var ret = checkNull('change');
            	if(ret=="false"){
            		return true;
            	}
            	layer.load(2);
            	var action ="";
                if("新增通讯录"==type){
                	action = "${pageContext.request.contextPath }/mailList/changeMailList.do?flag=N&t=" + Math.random();
                }else if("修改通讯录"==type){
                	action = "${pageContext.request.contextPath }/mailList/changeMailList.do?flag=E&t=" + Math.random();
                }
				$.ajax({
                    type: "POST",
                    url: action,
                    data: $('#mailListForm').serialize(),
                    dataType: "json",
                    success: function (result) {
                    	layer.closeAll('loading');
                    	var code = result.code;
                    	if(code==-3){	//登录用户失效
                       		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                       	}else if(code==-4){
                       		layer.alert("您没有操作权限！！！");
                       	}else if(code>0){
                       		layer.closeAll();
                       		layer.msg(result.msg);
                       		ajaxGetMailList(1,8);
	                    }else if(code==-2){ //excel校验不通过
	                    	errorInfo(result.msg);
	                    }else if(code==-1){ // 有错误
	                    	layer.alert(result.msg);
	                    }/* else if(code==-5){ // 手机号重复
                            layer.alert(result.msg);
                        } */
                        return false;
                    },
                    error: function (e) {
                    	layer.closeAll('loading');
                        layer.msg("操作失败！");
                        return true;
                    }
                });
            }
            ,btn2: function(index, layero){
            	layer.closeAll('loading');
            }
            ,cancel: function(){
            	layer.closeAll('loading');
            }
            ,area: ['800px', '500px']
        });
        $("#mailListIdU").val(id);  //动态赋值ID
        if(ret!=null&&type=='修改通讯录'){
            $("#nameU").val(ret.name);
            $("#regionU").val(ret.region);
            $("#positionU").val(ret.position);
            $("#machineNumberU").val(ret.machineNumber);
            $("#mobilePhoneU").val(ret.mobilePhone);
            $("#emailU").val(ret.email);
            $("#faxNumberU").val(ret.faxNumber);
            $("#addressU").val(ret.address);
            $("#sexU").val(ret.sex);
        }
    }
    
    //重置筛选条件
    function resetf(){
    	location.reload();
    }
    
    //是否已经点击了确定按钮，防止用户重复点击
	var clicked = false;
    //上传
    function openUpload() { 
    	clicked = true;
    	$("#uploadFileForm").remove();
        layer.open({
            title: ['请选择目标【通讯录Excel】文件', 'font-size:18px;'],
            type:1,
            content: uploadFileHtml, //这里content是一个普通的String
            btn: ['确认', '取消'],
            yes: function(index, layero){
            	if(clicked){
            		clicked = false;
            		var ret = uploadFile();
                	if(ret=='success'){
                		return false;	//关闭框
                	}
            	}
            }
            ,btn2: function(index, layero){
            	layer.closeAll('loading');
            }
            ,cancel: function(){
            	layer.closeAll('loading');
            }
            ,area: ['400px', '230px']
        });
       
    }
    
    function getProp(){
        obj = document.getElementsByName("choice");
        var check_val = "";
        for(k in obj){
            if(obj[k].checked)
                check_val = check_val+" "+ obj[k].value
        }
        return check_val;
    }
  	//所有选中的id
    var selectedIds = "";
    //全选或全不选
    $("#allAndNotAll").click(function() { 
        if (this.checked){  
            $("input[name='choice']:checkbox").each(function(){ 
                  $(this).attr("checked", true);  
            });
            layer.msg('拼命执行中，请稍等……', {icon: 16}, function(){
            	layer.closeAll();
            	layer.load(2);
            	//发送异步请求，获取数据
                sendRequest(pageContextPath + "/mailList/selectIds.do", null, function (jsonData) {
                    selectedIds = jsonData.ids;
                    layer.closeAll();
                });
            });
        } else {   
            $("input[name='choice']:checkbox").each(function() {   
                  $(this).attr("checked", false);  
            });
            selectedIds="";
        }  
    });
    
    function addTerminal(){
    	var terminal = $("#terminalCollectionU").val();
    	if(terminal.length>0 && terminal != "" && terminal != undefined){
    		var terminals = $("#terminal").val();
    		if(terminals.length>0){
    			if(terminals.indexOf(terminal)!=-1){
    			    layer.alert(terminal+"<br/>已经存在，请重新输入！");
    			    $("#terminalCollectionU").val("");
    			}else{
    			    $("#terminal").val(terminals+","+terminal);
    			}
    		}else{
    			$("#terminal").val(terminal);
    		}
    	}else{
    		layer.alert("不能添加空入货乙方！");
    	}
    	
    }
</script>
</body>
</html>